package dao

import (
	"go-demo/model"
	"gorm.io/gorm"
	"time"
)

// 增加关注记录
func AddFollow(followEvent model.FollowEvent) *gorm.DB {
	follows := model.FollowEvent{FollowId: followEvent.FollowId, FollowerId: followEvent.FollowerId, CreateTime: time.Now()}
	text := Db.Create(&follows)
	return text
}

// 删除关注记录
func DeleteFollow(followEvent model.FollowEvent) *gorm.DB {
	text := Db.Where("follow_id = ? and follower_id = ?", followEvent.FollowId, followEvent.FollowerId).Delete(&followEvent)
	return text
}

// 查询关注列表
func GetFollowList(followerId int64) (followEvent []model.FollowEvent) {
	var follows []model.FollowEvent
	Db.Where("follower_id = ?", followerId).Find(&follows)
	return follows
}

// 查询粉丝列表
func GetFollowerList(followId int64) []model.FollowEvent {
	var followers []model.FollowEvent
	Db.Where("follow_id = ?", followId).Find(&followers)
	return followers
}
